//
//  MNDConfirmTransferViewController.m
//  minidai
//
//  Created by 谭谭伟 on 17/5/17.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDConfirmTransferViewController.h"
#import "FTPopOverMenu.h"
#import "MNDTransferCalculateModel.h"
#import "MNDTransferSuccessViewController.h"
#import "MNDLoginUserModel.h"
#import "MNDWebViewController.h"

#import "MNDOpenDeposAlertViewController.h"
#import "MNDDepositAlertViewController.h"
#import "MNDOpenDepositoryViewController.h"
#import "MNDOpenDepositoryPaymentViewController.h"
#import "MNDOpenDepositoryTenderViewController.h"
#import "MNDOpenDepositoryTransferViewController.h"
#import "MNDRiskAssessWebViewController.h"
#import "MNDDepositWebViewController.h"
#import "MNDOpenTermsAuthViewController.h"

@interface MNDConfirmTransferViewController ()<UITextFieldDelegate>
//百分比
@property (weak, nonatomic) IBOutlet UILabel *precentLabel;
//标题
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
//可转本金
@property (weak, nonatomic) IBOutlet UILabel *brrowMoneyLabel;
//年化利率
@property (weak, nonatomic) IBOutlet UILabel *yearAprLabel;

//剩余期限
@property (weak, nonatomic) IBOutlet UILabel *deadLineLabel;
//转让金额
@property (weak, nonatomic) IBOutlet UITextField *transferMoneyTextField;
//应计利息
@property (weak, nonatomic) IBOutlet UILabel *interestLabel;
//转让费用
@property (weak, nonatomic) IBOutlet UILabel *transferCostLabel;
//转让收入
@property (weak, nonatomic) IBOutlet UILabel *transferIncomeLabel;
//转让价格
@property (weak, nonatomic) IBOutlet UILabel *transferPriceLabel;

/* 债权转让模型 */
@property (strong, nonatomic) MNDTransferCalculateModel *transferCalculateModel;
/* 允许转让金额 */
@property (strong, nonatomic) NSString *allowMoney;

@property (nonatomic, copy) NSString *userPhone;
//债权转让率
@property(nonatomic, strong) NSMutableArray *precentArr;
@end

@implementation MNDConfirmTransferViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
    [self loadData];
    [self initialBarbuttonItems];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self loadUserPhone];
    });
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

}

- (void)initialBarbuttonItems {
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                target:nil action:nil];
    //将宽度设为负值
    spaceItem.width = kScreenWidth < 414? -10 : -15;
    UIImage *itemImage = [UIImage imageNamed:@"notice_help_icon"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage: itemImage
                                                             style: UIBarButtonItemStylePlain
                                                            target: self
                                                            action: @selector(clickTransferRegularButton:)];
    item.tintColor = kColorOrange;
    
    if (@available(iOS 11.0, *)) {
        self.navigationItem.rightBarButtonItem = item;
    } else {
        self.navigationItem.rightBarButtonItems = @[spaceItem, item];
    }
}

//点击转让规则
-(void)clickTransferRegularButton:(id)sender {
    
    MNDWebViewController *webVC = [[MNDWebViewController alloc] init];
    webVC.webViewUrl = kCreditorHelp;
    webVC.naviBarHidden = YES;
    
    [self.navigationController pushViewController:webVC animated:YES];
}

- (void)setupUI {
    self.transferMoneyTextField.clearsOnBeginEditing = YES;
   // self.deadLineLabel.text = [NSString stringWithFormat:@"%@个月",self.detailModel.borrow_deadline];
    
    self.yearAprLabel.text = [NSString stringWithFormat:@"%@%%",self.yearApr];
    
//    NSString *allowMoney = [self.detailModel.allow_transfer_principal stringByReplacingOccurrencesOfString:@"," withString:@""];
    //监听输入金额的变化
    [[self.transferMoneyTextField rac_textSignal]subscribeNext:^(id x) {
        if(self.transferMoneyTextField.text.floatValue > self.allowMoney.floatValue){
            self.transferMoneyTextField.text = [NSString stringWithFormat:@"%@",self.allowMoney];
        }else {

        }
        //计算应计利息
        float interestNum = (self.transferMoneyTextField.text.floatValue/self.allowMoney.floatValue)*self.transferCalculateModel.creditor_accrued_interest.floatValue;
        
        self.interestLabel.text = [NSString stringWithFormat:@"%.2f",interestNum];
        
        //计算转让价格
        //折扣去掉百分号
        NSString *precnetStr = [self.precentLabel.text stringByReplacingOccurrencesOfString:@"%" withString:@""];
        float priceNum = self.transferMoneyTextField.text.floatValue * precnetStr.floatValue/100 + interestNum;
        self.transferPriceLabel.text = [NSString stringWithFormat:@"%.2f",priceNum];
        //计算转让费用
        float costNum = priceNum * self.transferCalculateModel.creditor_servefee_apr.floatValue;
        self.transferCostLabel.text = [NSString stringWithFormat:@"%.2f",costNum];
        
        //计算转让收入
        float transferIncomeNum = priceNum - costNum;
        self.transferIncomeLabel.text = [NSString stringWithFormat:@"%.2f",transferIncomeNum];

    }];
    
  
}

//投资计算参数获取
- (void)loadData {
    [NetworkProgressHUD showHud];
    
    WeakSelf(self);
    
    NSDictionary *params = [MNDSign signedParamWithDict:@{@"tender_id":self.tenderId}];
    
    [APIManager sendRequestWithPath:API_CREDITOR_TRANSFER parameters:params method:kXMHTTPMethodGET onSuccess:^(ResponseModel *responseModel) {
        if (responseModel.status == ResponseSuccess) {
            
            [NetworkProgressHUD hideHud];
            
            weakself.transferCalculateModel = [MNDTransferCalculateModel mj_objectWithKeyValues:responseModel.data];
            weakself.titleLabel.text = [weakself.transferCalculateModel.borrow objectForKey:@"title"];
            weakself.deadLineLabel.text = [NSString stringWithFormat:@"%@个月",[weakself.transferCalculateModel.borrow objectForKey:@"deadline_unit"]];
            weakself.brrowMoneyLabel.text = weakself.transferCalculateModel.sure_transfer_principal;
            //去掉金额逗号
            NSString *allowMoney = [weakself.transferCalculateModel.sure_transfer_principal stringByReplacingOccurrencesOfString:@"," withString:@""];
            weakself.transferMoneyTextField.text = allowMoney;
            weakself.allowMoney = allowMoney;
            //计算应计利息
            float interestNum = (weakself.transferMoneyTextField.text.floatValue/weakself.allowMoney.floatValue) * weakself.transferCalculateModel.creditor_accrued_interest.floatValue;
            weakself.interestLabel.text = [NSString stringWithFormat:@"%.2f",interestNum];
            
            //计算转让价格
            //折扣去掉百分号
            NSString *precnetStr = [weakself.precentLabel.text stringByReplacingOccurrencesOfString:@"%" withString:@""];
            float priceNum = weakself.transferMoneyTextField.text.floatValue * precnetStr.floatValue / 100 + interestNum;
            weakself.transferPriceLabel.text = [NSString stringWithFormat:@"%.2f",priceNum];
            //计算转让费用
            float costNum = priceNum * weakself.transferCalculateModel.creditor_servefee_apr.floatValue;
            weakself.transferCostLabel.text = [NSString stringWithFormat:@"%.2f",costNum];
            
            //计算转让收入
            float transferIncomeNum = priceNum - costNum;
            weakself.transferIncomeLabel.text = [NSString stringWithFormat:@"%.2f",transferIncomeNum];
        } else {
            [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
        }
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)clickPrecentSelectBtn:(UIButton *)sender {
    if (self.transferCalculateModel.transfer_apr_arr.count > 0) {
        self.precentArr = [[NSMutableArray alloc]initWithArray:self.transferCalculateModel.transfer_apr_arr];
    }else {
        NSArray *tempPrecentArr = @[@"100%",@"99%",@"98%",@"97%",@"96%",@"95%",@"94%",@"93%",@"92%",@"91%",@"90%",@"88%",@"98%",@"87%",@"86%",@"85%",@"84%",@"83%",@"82%",@"81%",@"80%"];
        self.precentArr = [[NSMutableArray alloc]initWithArray:tempPrecentArr];
    }
    
    FTPopOverMenuConfiguration *configuration = [FTPopOverMenuConfiguration defaultConfiguration];
    configuration.borderColor = [UIColor blackColor];
    configuration.textColor = [UIColor blackColor];
    configuration.tintColor = [UIColor whiteColor];
    WeakSelf(self);
    [FTPopOverMenu showForSender:sender withMenuArray:self.precentArr doneBlock:^(NSInteger selectedIndex) {
        weakself.precentLabel.text = self.precentArr[selectedIndex];
            //计算应计利息
            float interestNum = (weakself.transferMoneyTextField.text.floatValue/weakself.allowMoney.floatValue) * weakself.transferCalculateModel.creditor_accrued_interest.floatValue;
            weakself.interestLabel.text = [NSString stringWithFormat:@"%.2f",interestNum];
    
            //计算转让价格
            //折扣去掉百分号
            NSString *precnetStr = [weakself.precentLabel.text stringByReplacingOccurrencesOfString:@"%" withString:@""];
            float priceNum = weakself.transferMoneyTextField.text.floatValue * precnetStr.floatValue/100 + interestNum;
            weakself.transferPriceLabel.text = [NSString stringWithFormat:@"%.2f",priceNum];
            //计算转让费用
            float costNum = priceNum * weakself.transferCalculateModel.creditor_servefee_apr.floatValue;
            weakself.transferCostLabel.text = [NSString stringWithFormat:@"%.2f",costNum];
    
            //计算转让收入
            float transferIncomeNum = priceNum - costNum;
            weakself.transferIncomeLabel.text = [NSString stringWithFormat:@"%.2f",transferIncomeNum];
    } dismissBlock:^{
        
    }];
}

//确认转让
- (IBAction)clickConfirmTransferBtn:(UIButton*)sender {
    [NetworkProgressHUD showHud];
    //转让折扣去掉百分号
    NSString *precentStr = [self.precentLabel.text stringByReplacingOccurrencesOfString:@"%" withString:@""];
    float precentNum = precentStr.floatValue / 100;
    NSString *actulPrecentStr = [NSString stringWithFormat:@"%.2f",precentNum];
    NSDictionary *params = [MNDSign signedParamWithDict:@{@"tender_id": self.tenderId,
                                                          @"transfer_principal": self.transferMoneyTextField.text,
                                                          @"creditor_discount_apr": actulPrecentStr}];
    WeakSelf(self);
    [APIManager sendRequestWithPath:API_CREDITOR_TRANSFER parameters:params method:kXMHTTPMethodGET onSuccess:^(ResponseModel *responseModel) {
        if (responseModel.status == ResponseSuccess) {
            
            [NetworkProgressHUD hideHud];
            
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"TenderTransfer" bundle:nil];
            MNDTransferSuccessViewController *transferSuccessVC = [storyboard instantiateViewControllerWithIdentifier:@"MNDTransferSuccessViewController"];
            float transferNum = weakself.transferMoneyTextField.text.floatValue;
            transferSuccessVC.transferMoney = [NSString stringWithFormat:@"成功转让：￥%.2f",transferNum];
            [weakself.navigationController pushViewController:transferSuccessVC animated:YES];
            
        } else {
            NSDictionary *msgDict = responseModel.msg;
            if ([msgDict.allKeys containsObject:@"sign"]) {
                [NetworkProgressHUD hideHud];
                if ([responseModel.msg[@"sign"] isEqualToString:kOpenAccount] ||
                    [responseModel.msg[@"sign"] isEqualToString:kSetPassword] ||
                    [responseModel.msg[@"sign"] isEqualToString:kSignPayment] ||
                    [responseModel.msg[@"sign"] isEqualToString:kSignAutoTender] ||
                    [responseModel.msg[@"sign"] isEqualToString:kSignAutoTransfer] ||
                    [responseModel.msg[@"sign"] isEqualToString:kRiskEvaluation] ||
                    [responseModel.msg[@"sign"] isEqualToString:kBandcard] ||
                    [responseModel.msg[@"sign"] isEqualToString:kExpiredSignPayment] ||
                    [responseModel.msg[@"sign"] isEqualToString:kExpiredAutotender]
                    ) {
                    [weakself showDepositAlertWithModel:responseModel];
                }else if([responseModel.msg[@"sign"] isEqualToString:@"tender_money"]) {
                    [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
                }
                
            } else {
                [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
            }
        }
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
}

- (void)showDepositAlertWithModel:(ResponseModel *)response {
    NSString *signStr = response.msg[@"sign"];
    
    //开通存管账户
    if ([signStr isEqualToString:kOpenAccount]) {
        
        [self showOpenAccountAlertWithModel:response];
        return;
    }
    
    //风险等级未评测
    if ([signStr isEqualToString:kRiskEvaluation]) {
        
        [self showRiskAlertView:response.data[@"risk_url"]];
        return;
    }
    
    __weak MNDOpenDeposAlertViewController *alertVC = [UIStoryboard viewControllerWithIdentifier:[MNDOpenDeposAlertViewController description]];
    
    __weak UIView *alertView = alertVC.view;
    [KeyWindow addSubview:alertView];
    [self.tabBarController addChildViewController:alertVC];
    
    WeakSelf(self);
    
    [alertVC.confirmButton bk_addEventHandler:^(id sender) {
        [alertView removeFromSuperview];
        [alertVC removeFromParentViewController];
        
        [weakself toOpenDepositoryWithModel:response];
        
    } forControlEvents:UIControlEventTouchUpInside];
    
    alertVC.alertMessage = response.msg[@"error"];
    alertVC.alertType = response.msg[@"sign"];
}

- (void)showOpenAccountAlertWithModel:(ResponseModel *)response {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    __weak MNDDepositAlertViewController *alertVC = [storyboard instantiateViewControllerWithIdentifier:[MNDDepositAlertViewController description]];
    __weak UIView *springView = alertVC.view;
    [KeyWindow addSubview:springView];
    [self.tabBarController addChildViewController:alertVC];
    
    __weak typeof(self) weakSelf = self;
    
    [alertVC.depositBtn bk_addEventHandler:^(id sender) {
        [springView removeFromSuperview];
        [alertVC removeFromParentViewController];
        [weakSelf toOpenDepositoryWithModel:response];
        
    } forControlEvents:UIControlEventTouchUpInside];
    
    [alertVC.closeBtn bk_addEventHandler:^(id sender) {
        
        [UIView animateWithDuration:0.5 animations:^{
            alertVC.alertContainerView.frame = CGRectMake(alertVC.alertContainerView.frame.origin.x, kScreenHeight, alertVC.alertContainerView.frame.size.width, alertVC.alertContainerView.frame.size.height);
            alertVC.closeBtn.frame = CGRectMake(alertVC.closeBtn.frame.origin.x, kScreenHeight, alertVC.closeBtn.frame.size.width, alertVC.closeBtn.frame.size.height);
        } completion:^(BOOL finished) {
            [springView removeFromSuperview];
            [alertVC removeFromParentViewController];
        }];
    } forControlEvents:UIControlEventTouchUpInside];
}

- (void)toOpenDepositoryWithModel:(ResponseModel *)response {
    
    NSInteger index = [self.navigationController.viewControllers indexOfObject:self];
    
    NSString *signStr = response.msg[@"sign"];
    //开通存管
    if ([signStr isEqualToString:kOpenAccount]) {
        MNDOpenDepositoryViewController *realVC = [UIStoryboard viewControllerWithIdentifier:[MNDOpenDepositoryViewController description]];
        realVC.fromNaviIndex = index;
        
        [self.navigationController pushViewController:realVC animated:YES];
        
        return;
    }
    //设置交易密码
    if ([signStr isEqualToString:kSetPassword]) {
        
        [self loadPaymentPassword];
        return;
    }
    //授权三合一
    if ([signStr isEqualToString:kSignPayment] || [signStr isEqualToString:kExpiredSignPayment] || [signStr isEqualToString:kSignAutoTender] || [signStr isEqualToString:kExpiredAutotender] || [signStr isEqualToString:kSignAutoTransfer]) {
        MNDOpenTermsAuthViewController *openTermsAuthVC = [UIStoryboard viewControllerWithIdentifier:@"MNDOpenTermsAuthViewController"];
        openTermsAuthVC.fromNaviIndex = index;
        [self.navigationController pushViewController:openTermsAuthVC animated:YES];
        return;
    }
//    //设置缴费授权
//    if ([signStr isEqualToString:kSignPayment] || [signStr isEqualToString:kExpiredSignPayment]) {
//        
//        MNDOpenDepositoryPaymentViewController *paymentVC = [UIStoryboard viewControllerWithIdentifier:[MNDOpenDepositoryPaymentViewController description]];
//        paymentVC.fromNaviIndex = index;
//        
//        [self.navigationController pushViewController:paymentVC animated:YES];
//        
//        return;
//    }
//    //设置自动投标
//    if ([signStr isEqualToString:kSignAutoTender] || [signStr isEqualToString:kExpiredAutotender]) {
//        
//        MNDOpenDepositoryTenderViewController *tenderVC = [UIStoryboard viewControllerWithIdentifier:[MNDOpenDepositoryTenderViewController description]];
//        tenderVC.isResign = [signStr isEqualToString:kExpiredAutotender];
//        if (self.userPhone.length > 0) {
//            tenderVC.fromNaviIndex = index;
//            tenderVC.phoneNumber = self.userPhone;
//            
//            [self.navigationController pushViewController:tenderVC animated:YES];
//        } else {
//            [self loadUserPhone];
//        }
//        return;
//    }
//    //设置自动债转
//    if ([signStr isEqualToString:kSignAutoTransfer]) {
//        
//        MNDOpenDepositoryTransferViewController *transferVC = [UIStoryboard viewControllerWithIdentifier:[MNDOpenDepositoryTransferViewController description]];
//        transferVC.messageStr = response.msg[@"error"];
//        if (self.userPhone.length > 0) {
//            transferVC.fromNaviIndex = index;
//            transferVC.phoneNumber = self.userPhone;
//            
//            [self.navigationController pushViewController:transferVC animated:YES];
//        } else {
//            [self loadUserPhone];
//        }
//        return;
//    }
}

/**
 获取存管手机号
 */
- (void)loadUserPhone {
    
    WeakSelf(self);
    
    NSDictionary *param = [MNDSign signedParam];
    [APIManager sendRequestWithPath:API_DEPOSIT_GET_PHONE parameters:param method:kXMHTTPMethodGET onSuccess:^(ResponseModel *responseModel) {
        if (responseModel.status == ResponseSuccess) {
            weakself.userPhone = responseModel.data;
        } else {
            NSDictionary *dict = responseModel.msg;
            if (dict && dict.count > 0) {
                [NetworkProgressHUD showHudMsg:dict[@"error"]];
                
            } else {
                [NetworkProgressHUD showHudMsg:@"获取数据失败，请重试"];
            }
        }
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
}

- (void)showRiskAlertView:(NSString *)riskUrl {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您还没有完成[出借用户风险等级测评]，根据金融监管政策要求，用户需要先完成评估才能出借。" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"去测评" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSInteger index = [self.navigationController.viewControllers indexOfObject:self];
        
        MNDRiskAssessWebViewController *riskVC = [[MNDRiskAssessWebViewController alloc]init];
        riskVC.webViewUrl = riskUrl;
        riskVC.indexOfViewController = index;
        riskVC.title = @"风险测评";
        [self.navigationController pushViewController:riskVC animated:YES];
    }];
    [alert addAction:cancelAction];
    [alert addAction:action];
    
    [self presentViewController:alert animated:YES completion:^{
        
    }];
}

/**
 设置交易密码
 */
- (void)loadPaymentPassword {
    
    [NetworkProgressHUD showHud];
    
    WeakSelf(self);
    
    [APIManager sendRequestWithPath:API_DEPOSIT_SET_PASSWORD parameters:[MNDSign signedParamWithDict:@{@"channel": @"app"}] method:kXMHTTPMethodPOST onSuccess:^(ResponseModel *responseModel) {
        
        if (responseModel.status == ResponseSuccess) {
            [NetworkProgressHUD hideHud];
            MNDDepositWebViewController *webVC = [UIStoryboard viewControllerWithIdentifier:[MNDDepositWebViewController description]];
            webVC.htmlStr = responseModel.data;
            webVC.title = @"设置交易密码";
            NSInteger index = [weakself.navigationController.viewControllers indexOfObject:weakself];
            webVC.fromNaviIndex = index;
            
            [weakself.navigationController pushViewController:webVC animated:YES];
        } else {
            [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
        }
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
}

//设置textfield输入内容
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField == self.transferMoneyTextField) {
        NSScanner      *scanner    = [NSScanner scannerWithString:string];
        NSCharacterSet *numbers;
        NSRange         pointRange = [textField.text rangeOfString:@"."];
        
        if ( (pointRange.length > 0) && (pointRange.location < range.location  || pointRange.location > range.location + range.length) )
        {
            numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
        }
        else
        {
            numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
        }
        
        if ( [textField.text isEqualToString:@""] && [string isEqualToString:@"."] )
        {
            return NO;
        }
        
        short remain = 2; //默认保留2位小数
        
        NSString *tempStr = [textField.text stringByAppendingString:string];
        NSUInteger strlen = [tempStr length];
        if(pointRange.length > 0 && pointRange.location > 0){ //判断输入框内是否含有“.”。
            if([string isEqualToString:@"."]){ //当输入框内已经含有“.”时，如果再输入“.”则被视为无效。
                return NO;
            }
            if(strlen > 0 && (strlen - pointRange.location) > remain+1){ //当输入框内已经含有“.”，当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数，则视当次输入无效。
                return NO;
            }
        }
        NSRange zeroRange = [textField.text rangeOfString:@"0"];
        if(zeroRange.length == 1 && zeroRange.location == 0){ //判断输入框第一个字符是否为“0”
            if(![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1){ //当输入框只有一个字符并且字符为“0”时，再输入不为“0”或者“.”的字符时，则将此输入替换输入框的这唯一字符。
                textField.text = string;
                return NO;
            } else{
                if(pointRange.length == 0 && pointRange.location > 0){ //当输入框第一个字符为“0”时，并且没有“.”字符时，如果当此输入的字符为“0”，则视当此输入无效。
                    if([string isEqualToString:@"0"]){
                        return NO;
                    }
                }
            }
        }
        
        NSString *buffer;
        if ( ![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0) )
        {
            return NO;
        }
        
    }
    
    return YES;
}



@end
